package person.bing.fbcloud.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: mengfanbing
 * @date: 2020/8/11 9:57
 */
public class Q130 {
    public static void main(String[] args) {
        char[][] param = {{'X','O','X','O','X','O'},{'O','X','O','X','O','X'},{'X','O','X','O','X','O'},{'O','X','O','X','O','X'}};
        solve(param);
        System.out.println(param);
    }

    public static void solve(char[][] board) {
        int boardLength = board.length;
        int firstArrayLength = 0;
        if (boardLength > 0){
            firstArrayLength = board[0].length;
        }
        for(int i=1;i<boardLength-1;i++){
            for(int j=1;j<firstArrayLength-1;j++){
                char element = board[i][j];
                if (element == 'O'){
                    List<Integer> list = new ArrayList<>();
                    int z1 = i-1;
                    while (z1>=0){
                        if (board[z1][j] == 'X'){
                            list.add(1);
                            break;
                        }else {
                            z1--;
                        }
                    }
                    int z2 = j-1;
                    while (z2>=0){
                        if (board[i][z2] == 'X'){
                            list.add(1);
                            break;
                        }else {
                            z2--;
                        }
                    }
                    int z3 = i+1;
                    while (z3<boardLength){
                        if (board[z3][j] == 'X'){
                            list.add(1);
                            break;
                        }else {
                            z3++;
                        }
                    }
                    int z4 = j+1;
                    while (z4<firstArrayLength){
                        if (board[i][z4] == 'X'){
                            list.add(1);
                            break;
                        }else {
                            z4++;
                        }
                    }
                    if (list.size() == 4){
                        board[i][j] = 'X';
                    }
                }
            }
        }
//        System.out.println(board);
    }

}
